package com.hw

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

//1、统计班级人数
//2、统计学生的总分

object Demo1CountStudent {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("CountStudent")
    val sc = new SparkContext(conf)

    val valueRDD: RDD[String] = sc.textFile("hadoop_code/src/data/students.txt")

    valueRDD.map(
      line =>{
        val clazz: String = line.split(",").last
        (clazz,1)
      }
    ).reduceByKey(
      (x,y)=>{
        x+y
      }
    ).map{
      case(clazz:String,count:Int) =>
        s"$clazz\t$count"
    }.foreach(println)

  }
}
